package com.shababeach.travel.service.impl;

import com.shababeach.travel.entity.User;
import com.shababeach.travel.repository.UserRepository;
import com.shababeach.travel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public Map<String, Object> getUserInfo(Long userId) {
        User user = getUser(userId);
        
        Map<String, Object> userInfo = new HashMap<>();
        userInfo.put("userId", user.getId().toString());
        userInfo.put("nickName", user.getNickName());
        userInfo.put("avatarUrl", user.getAvatarUrl());
        userInfo.put("gender", user.getGender());
        userInfo.put("visitCount", user.getVisitCount());
        userInfo.put("likeCount", user.getLikeCount());
        userInfo.put("favoriteCount", user.getFavoriteCount());
        
        return userInfo;
    }

    @Override
    public User getUser(Long userId) {
        return userRepository.findById(userId)
                .orElseThrow(() -> new RuntimeException("用户不存在"));
    }
} 